package com.smh.demo1.a17;

import com.smh.demo1.a17.annotation.Token;
import com.smh.demo1.a17.annotation.Yml;
import com.smh.demo1.common.LogColour;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author shiminghui
 * @date 2025/4/24 16:54
 * @description: TODO
 */
@Controller
public class TestController {
    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @GetMapping("/test")
    public String test() {
        log.info(LogColour.Blue("test"));
        return null;
    }

    @GetMapping("/test2")
    public ModelAndView test2() {
        log.info(LogColour.Blue("test2"));
        return null;
    }

    @PostMapping("/test3")
    public ModelAndView test3(@RequestParam("id") Long id) {
        log.info(LogColour.Blue("test3: " + id));
        return null;
    }

    @DeleteMapping("/test4")
    public ModelAndView test4(@Token String token) {
        log.info(LogColour.Blue("test4: " + token));
        return null;
    }

    @PutMapping("/test5")
    @Yml
    public User test5() {
        User user = new User();
        user.setAge(18);
        user.setName("shiminghui");
        user.setId(1L);
        log.info(LogColour.Blue("test5: " + user));
        return user;
    }


    static class User {
        private Long id;
        private String name;
        private Integer age;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
